package com.example.erat.controller;

import com.example.erat.common.Result;
import com.example.erat.entity.Student;
import com.example.erat.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "学生管理接口")
@RestController
@Slf4j
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("获取学生列表")
    @GetMapping("/list")
    public Result<List<Student>> getStudentList() {
        List<Student> students = studentService.list();
        return Result.success(students);
    }

    @ApiOperation("导入学生列表")
    @PostMapping("/import")
    public Result<String> importStudents(MultipartFile file) {
        studentService.importStudents(file);
        return Result.success("导入成功");
    }


}
